<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/fns.tld" prefix="fns" %>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <jsp:include page="/resources/inc/head.jsp" />
    <link href="${basePath}/resources/zheng-admin/plugins/zTree_v3/css/demo.css" rel="stylesheet"/>
    <link href="${basePath}/resources/zheng-admin/plugins/zTree_v3/css/metroStyle/metroStyle.css" rel="stylesheet"/>
</head>
<body>
<form class="layui-form layui-form-pane" id="_form">
    <div class="layui-form-item">
        <label class="layui-form-label">培训名称</label>
        <div class="layui-input-block">
            <input type="text" name="trainName" lay-verify="required" autocomplete="off" placeholder="请输入培训名称"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">讲师选择</label>
        <div class="layui-input-block">
            <input type="radio" name="insideInstructor" value="true" title="内部讲师" lay-filter="instructor" checked>
            <input type="radio" name="insideInstructor" value="false" title="外部讲师" lay-filter="instructor">
        </div>
    </div>
    <div class="layui-form-item" id="trainInstructorId">
        <label class="layui-form-label">内部讲师选择</label>
        <div class="layui-input-block ztreeDiv">
            <input type="text" readonly="readonly"
                   placeholder="请选择内部讲师" class="layui-input" onclick="ZtreeCommon.showMenu(this)"
                   ztreeId="instructorTree">
            <input type="hidden" name="trainInstructorId" ztreeId="instructorTree">
        </div>
        <div class="menuContent" style="display:none; position: absolute;z-index: 10000">
            <ul id="instructorTree" class="ztree" style="margin-top:0; width:220px;"></ul>
        </div>
    </div>
    <div class="layui-form-item" hidden="hidden" id="trainInstructor">
        <label class="layui-form-label">外部讲师姓名</label>
        <div class="layui-input-block">
            <input type="text" name="trainInstructor" autocomplete="off" placeholder="请输入讲师姓名"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">培训员工</label>
        <div class="layui-input-block ztreeDiv">
            <input type="text" readonly="readonly" lay-verify="required"
                   placeholder="请选择培训员工" class="layui-input" onclick="ZtreeCommon.showMenu(this)" ztreeId="ztree">
            <input type="hidden" name="joinInfo" ztreeId="ztree">
        </div>
        <div class="menuContent" style="display:none; position: absolute;z-index: 10000">
            <ul id="ztree" class="ztree" style="margin-top:0; width:220px;"></ul>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">培训开始时间</label>
        <div class="layui-input-block">
            <input type="text" name="beginTime" autocomplete="off"
                   placeholder="请选择培训开始时间" lay-verify="required"
                   class="layui-input date-select" readonly="readonly">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">培训地点</label>
        <div class="layui-input-block">
            <input type="text" name="trainPlace" lay-verify="required" autocomplete="off" placeholder="请输入培训地点"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">备注</label>
        <div class="layui-input-block">
            <textarea name="remark" autocomplete="off" placeholder="请输入备注" class="layui-textarea"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="float: right">
            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
        </div>
    </div>
</form>
<jsp:include page="/resources/inc/pageFooter.jsp" />
<script src="${basePath}/resources/zheng-admin/js/my-ztree-common.js"></script>
<script>
    var zNodes = getOrganizationTree(false, true);
    var userNodes = [];
    $(zNodes).each(function (index, node) {
        var userNode = $.extend(true, {}, node);
        userNodes.push(userNode);
    });
    $(userNodes).each(function (index, node) {
        if (!node.isUser) {
            node.nocheck = true
        }
    });
    $(function () {
        layui.use('laydate', function () {
            laydate = layui.laydate;
            $(".date-select").each(function (index, input) {
                laydate.render({
                    elem: this //指定元素
                    , theme: '#393D49'
                    , type: 'datetime'
                });
            });
        });
        FormCommon.initForm({
            url: '${basePath}/oa/hr/train/create',
            subContentType: "json",
            editData: function (data) {
                data.beginTime = new Date(data.beginTime);
                var insideInstructor = data.insideInstructor;
                if (insideInstructor == "true") {
                    if (data.trainInstructorId == null && data.trainInstructorId.length < 1) {
                        throw "请选择内部讲师"
                    }
                } else {
                    if (data.trainInstructor == null && data.trainInstructor.length < 1) {
                        throw "请输入外部讲师姓名"
                    }
                }
                return data;
            }
        });
        layForm.on('radio(instructor)', function (data) {
            if (data.value == "true") {
                $("#trainInstructor").hide();
                $("#trainInstructorId").show();
            } else {
                $("#trainInstructor").show();
                $("#trainInstructorId").hide();
            }
        });
        $.fn.zTree.init($("#ztree"), ZtreeCommon.checkBoxSetting, zNodes);
        $.fn.zTree.init($("#instructorTree"), ZtreeCommon.radioSetting, userNodes);

    });
</script>
</body>
</html>
